<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .father {
            width: 200px;
            height: 200px;
            background: green;
            margin: 150px;
            position: relative;
        }

        .son {
            width: 100px;
            height: 100px;
            background: lightsalmon;
            margin-left: 50px;
        }

        .box {
            width: 100px;
            height: 100px;
            border: 5px dotted green;
            margin: 20px;
            padding: 30px;
        }
    </style>
</head>

<body>
    <div class="father">
        <div class="son"></div>
    </div>

    <div class="box">

    </div>
    <script>
        var father = $(".father")[0];
        var son = $(".son")[0];
        var box = $(".box")[0];
        // offsetLeft 该元素距离父元素的左边的距离
        // offsetTop 该元素距离父元素的上边的距离

        console.log(father.offsetTop);//150
        console.log(father.offsetLeft);//150
        
        console.log(son.offsetLeft);//50
        console.log(son.offsetTop);//0


        // offsetWidth = 元素的width + 2*padding + 2*border
        // offsetHeight = 元素的height + 2*padding + 2*border
        console.log(box.offsetWidth);//170
        console.log(box.offsetHeight);//170
        function $(select) {
            return document.querySelectorAll(select);
        }
    </script>
</body>

</html>